; generate sine table - 256 steps, range 0x80 - 0x7f

stack_a	equ 0x2d28
fp_to_a equ 0x2dd5

mksine
	ld a,64
	out (254),a		; a good opportunity to set the border to black
	call stack_a
	rst 0x28
	db 0xc4	;store 64 into mem 4
	db 0xa3	;push half-pi
	db 0x01	;exchange
	db 0x05	;divide (-> pi/128)
	db 0xc3 ;store pi/128 into mem 3
	db 0x02	;discard it	(nice but unnecessary?)
	db 0xa0 ;push 0
	db 0x38	;return

	ld hl,bigsine
sinelp
	push hl

	ld h,0x59	; draw background-and-progress-bar over top 2/3 of screen
	ld (hl),b
byte_0x25: dec h	; we want to mercilessly abuse a byte 0x25 for the music player
	ld (hl),b

	rst 0x28
	db 0xe3	;recall pi/128
	db 0x0f	;add
	db 0x31	;duplicate
	db 0x1f	;sine
	db 0xe4	;recall 64 from mem 4
	db 0xa1	;push 1
	db 0x03	;subtract 1 to give 63
	db 0x04	;multiply
	db 0x31	;duplicate
	db 0x0f	;add (ie double the result to scale to 0x7f)
;	db 0xe4	;recall 64 again
;	db 0x0f ;add again
	db 0x38	;return
	call fp_to_a
	jr z,noneg
	neg
noneg

	pop hl
	ld (hl),a
	inc l
	jr nz,sinelp
